package main

import (
	"../model"
	"fmt"
	"net"
	"time"
)

func initUserDao() {
	model.MyUserDao = model.NewUserDao(pool)
}

func init() {
	initPool("localhost:6379", 16, 0, 300*time.Second)
	initUserDao()
	fmt.Println("打开服务...")
}

func main() {

	fmt.Println("服务器在8888端口监听...")

	listen, err := net.Listen("tcp", "0.0.0.0:8888")

	if err != nil {
		fmt.Printf("listen error = %v", err)
		return
	}

	for {
		conn, err := listen.Accept()
		if err != nil {
			fmt.Printf("accept error = %v", err)
			return
		}

		go proccess(conn)
	}

}

func proccess(conn net.Conn) {
	defer conn.Close()

	mp := &Processor{
		Conn: conn,
	}

	err := mp.StartProcess()
	if err != nil {
		fmt.Println("客户端和服务器通迅错误 = ", err)
	}
}
